<template>
  <van-button
    :icon="value === 1 ? 'good-job' : 'good-job-o'"
    :class="{liked: value === 1}" 
    @click="onCollect"
    :loading="loading"
  />
</template>

<script>

import {addLike} from "@/api/article"
import {deleteLike} from'@/api/article'
export default {
  name:"LikeArticle",
  components: {},
  props: {
    value: {
      type: Number,  //点赞的数据是-1,0,1（点赞）这样的数据
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data() {
    return {
      loading: false
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async onCollect() {
     try {
         let index =-1
if(this.value==-1){ const res= await addLike( this.articleId)
  index = 1
}
else{
    const res = await deleteLike(this.articleId)

}

       this.$emit('input',index)

     } catch (error) {
         console.log(error);
         
     }
    }
  }
};
</script>

<style scoped lang="less">
.liked {
  .van-icon {
    color: #e5645f!important;
  }
}
</style>